import 'package:freedom/page/mahjong/common/mahjong_context.dart';
import 'package:freedom/page/mahjong/common/message_content.dart';
import 'package:freedom/page/mahjong/event/user_bar_event.dart';
import 'package:freedom/page/mahjong/message/abstract_action_message.dart';
import 'package:freedom/util/voice_message_sound.dart';

class BarAction extends AbstractMessageActionHandler<MahjongMessage> {
  @override
  void doMessage(MahjongMessage message) {
    var userDiskInfo = MahjongContext.getUserStateById(message.exeActionUid);
    if (userDiskInfo == null) {
      return;
    }

    /**
     * @type 1 碰牌,2 暗杠, 3 明杠 , 4 点杠
     * 
     * 
     * 对指定用户的牌 进行修改
     */

    int cardCode = message.cardCode!;
    MahjongContext.postUserEvent<UserBarEvent>(message.exeActionUid,
        UserBarEvent(cardCode, message.cardType, message.sourceBySeq));
    MahjongContext().reInitHuCardTips(false);
    MahjongContext.mahjongGameIndex.directionComponent!.current =
        userDiskInfo.direction;
    MahjongContext.mahjongGameIndex.directionComponent!.reckon = 30;
    MahjongContext.mahjongGameIndex.addBBTH('gang', userDiskInfo.direction);
    // 当下发碰的时候  直接播放声音
    VoiceMessageSound().play("BAR", close: () {});
  }
}
